<?php

namespace app\common\model\shopro;

use app\admin\model\shopro\goods\Goods;
use think\Model;

/**
 * 排队表
 */
class CarQueue extends Model
{

    // 开启自动写入时间戳字段
    protected $name = 'shopro_car_queue';
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    // 追加属性
    protected $append = [
    ];
    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    public function goods(){
        return $this->belongsTo(Goods::class, 'goods_id', 'id');
    }
    public function getCreatetimeAttr($value,$data)
    {
       if(isset($data['createtime'])){
           $value = date('Y-m-d H:i:s',$data['createtime']);
       }
       return $value;
    }
}
